﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoolERP_Entities;
using CoolERP_BLL;
using CoolERP_Common;

namespace CoolERP_Web.User
{
    [PermissionCheck(false)]
    public partial class ModifyPwd : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave_Click(object sender, ImageClickEventArgs e)
        {
            using (UsersBLL uBLL = new UsersBLL())
            {
                Users user = uBLL.GetEntity(t => t.Id == this.currentUser.UserID);
                if (user.Password != MD5Helper.EncryptString(txtOldPwd.Text.Trim()))
                {
                    labResult.Text = "旧密码错误";
                }
                else
                {
                    user.Password = MD5Helper.EncryptString(txtNewPwd.Text.Trim());
                    if (uBLL.Update(user))
                        labResult.Text = "修改成功";
                    else
                        labResult.Text = "修改失败";
                }
            }
        }
    }
}